package com.ebring.shareEducation.controller;

import com.ebring.shareEducation.bean.RoleMenu;
import com.ebring.shareEducation.bean.RoleMenuMiddle;
import com.ebring.shareEducation.service.RoleMenuMiddleService;
import com.ebring.shareEducation.utils.RspMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://wangliang.vipgz1.idcfengye.com", maxAge = 3600)
@Api(value = "角色菜单对应管理" ,tags = {"角色菜单对应管理接口"})
public class RoleMenuMiddleController {

    @Autowired
    private RoleMenuMiddleService roleMenuMiddleService;
    /**
     *查询角色对应的菜单
     */
    @GetMapping("/roleMenuMiddle/selectById/{roleId}")
    @ApiOperation(value="查询角色对应的菜单", notes="查询角色对应的菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "roleId", value = "角色编号", required = true, dataType = "String"),
    })
    public RspMsg<List<RoleMenuMiddle>> selectRoleMenuMiddleId(@PathVariable("roleId") String roleId) {
        return roleMenuMiddleService.selectRoleMenuMiddleId(roleId);
    }

    /**
     *为角色分配菜单
     */
    @PostMapping("/roleMenu/insert")
    @ApiOperation(value="为角色分配菜单", notes="为角色分配菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "roleId", value = "角色编号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query",name = "menuIds", value = "菜单编号", required = true, dataType = "String[]"),

    })
    public RspMsg<RoleMenu> allotMenu(String roleId, String[] menuIds) {
        return  roleMenuMiddleService.insertRoleMenu(roleId, menuIds);
    }
}